package com.woniuxy01;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * @author 作者
 * @create 2025-11-07 14:52
 */
public class Test07 {
    public static void main(String[] args) {
//        getList().stream()
//                .map(account -> new StringBuilder(account.getAname()))
//                .forEach(System.out::println);

        getList().stream()
                .map(Account::getAname)
                .map(String::toUpperCase)
                .forEach(System.out::println);
        getList().stream()
                .map(account -> account.getAname().toUpperCase())
                .forEach(System.out::println);
    }

    private static void test08() {
        getList().forEach(account -> System.out.println(account));
        System.out.println("----------------------");
        //(参数)->输出语句(参数)
        //省略了参数，参数作为方法体中调用方法的参数
        getList().forEach(System.out::println);
    }

    private static void test07() {
        getList().stream()
                //(参数)->{return 参数.实例方法;}           类::实例方法
//                .map(account -> account.getAname())
                .map(Account::getAname)
                .forEach(System.out::println);
    }

    private static void test06() {
        getList().stream()
                .filter(account -> account.getSex().equals("男")
                        && account.getAname().startsWith("刘"))
                .map(account-> account.getAname().toUpperCase())
                .map(str->str.length())
                .forEach(str-> System.out.println(str));

//        Integer reduce = getList().stream()
//                .filter(account -> account.getSex().equals("男")
//                        && account.getAname().startsWith("刘"))
//                .map(account -> account.getAname().toUpperCase())
//                .map(str -> str.length())
//                .reduce(0, (a, b) -> a + b);
//        System.out.println(reduce);
    }

    private static void test05() {
        //查询集合中满足如下条件的数据：男，姓刘，只要用户名 List<String>
        List<String> list = getList().stream()
                .filter(account -> account.getSex().equals("男")
                        && account.getAname().startsWith("刘"))
                .map(account-> account.getAname().toUpperCase())
//                .map(str->str.toUpperCase())
                .toList();
        System.out.println(list);
    }

    private static void test04() {
        //查询集合中满足如下条件的数据：男，姓刘，只要用户名 List<String>
        List<String> list = getList().stream()
                .filter(account -> account.getSex().equals("男")
                        && account.getAname().startsWith("刘"))
                //map方法需要一个Function接口，参数Account,返回值String
                .map(new Function<Account, String>() {
                    @Override
                    public String apply(Account account) {
                        return account.getAname();
                    }
                })
                .toList();
        System.out.println(list);
    }

    private static void test02() {
        getList().stream()
                .filter(account -> account.getAname().startsWith("刘"))
                .filter(account -> account.getSex().equals("男"))
                .forEach(account -> System.out.println(account));
    }

    private static void test01() {
        getList().forEach(account -> System.out.println(account));

        getList().stream()
                .forEach(account -> System.out.println(account));
    }

    static List<Account> getList() {
        Account a1 = new Account(10, "刘口水a", "123", "男", 2000, "成都市", "18868036677", new Date());
        Account a2 = new Account(102, "刘言b", "123", "女", 8000, "宜宾市", "18868036688", new Date());
        Account a3 = new Account(101, "刘备a", "123", "男", 20000, "成都市", "18868036557", new Date());
        Account a4 = new Account(30, "杜脐眼", "123", "女", 28000, "宜宾市", "18868036337", new Date());
        Account a5 = new Account(50, "杜子谦", "123", "男", 6000, "成都市", "18868032277", new Date());
        Account a6 = new Account(20, "杜甫", "123", "男", 20000, "乐山市", "18868030077", new Date());
        Account a7 = new Account(14, "杨洋", "123", "男", 10000, "成都市", "18868036637", new Date());

        List<Account> list = new ArrayList<Account>();
        list.add(a1);
        list.add(a2);
        list.add(a3);
        list.add(a4);
        list.add(a5);
        list.add(a6);
        list.add(a7);
        return list;
    }
}
